package com.rec.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rec.entity.Memberships;
import com.rec.service.MembershipsService;

@RestController
@RequestMapping("memberships")
@CrossOrigin
public class MembershipsController {
		@Autowired
		private MembershipsService s;
		@RequestMapping("getAll")
		public Map<String,Object> getAll(){
			return s.getAll();
		}
		/**
		 * department   specialty  degree
		 * 
		 * memberships/add
		 * memberships/update
		 */
		@RequestMapping("getSearch")
		public Map<String,Object> getBySearch(String department,String specialty
				,String degree,Integer page, Integer limit){
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("department", department);
			params.put("specialty", specialty);
			params.put("degree", degree);
			limit = limit == null ? 10 : limit;
			page = page == null ? 0 : page - 1;
			params.put("limit", limit);
			params.put("page", page);
			return s.getSearch(params);
		}
		@RequestMapping("add")
		public Map<String,Object> addnew(Memberships m){
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("mem", m);
			return s.addNew(params);
		}
		@RequestMapping("update")
		public Map<String,Object> update(Integer id,String department,String specialty
				,String degree){
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("id", id);
			params.put("department", department);
			params.put("specialty", specialty);
			params.put("degree", degree);
			return s.updateM(params);
		}
		
		
		
}
